
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>网络函数 · EasyClick开发文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="thread-api.html" />
    
    
    <link rel="prev" href="file-api.html" />
    

    
        <link rel="shortcut icon" href="/zh-cn/images/ico.png" type="image/x-icon">
    
    
    
    
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="/zh-cn/images/ico.png">
    
    
        
    
    
        
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../features.html">
            
                <a href="../features.html">
            
                    
                    特性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../changelog.html">
            
                <a href="../changelog.html">
            
                    
                    更改记录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../getting-start.html">
            
                <a href="../getting-start.html">
            
                    
                    开始
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <a target="_blank" href="https://www.bilibili.com/video/bv1W54y1Q7JG">
            
                    
                    视频教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="devtools/dev-tools.html">
            
                <a href="devtools/dev-tools.html">
            
                    
                    开发工具介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="devtools/dev-tools-install.html">
            
                <a href="devtools/dev-tools-install.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="devtools/dev-tools-project.html">
            
                <a href="devtools/dev-tools-project.html">
            
                    
                    工程相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="devtools/dev-tools-device.html">
            
                <a href="devtools/dev-tools-device.html">
            
                    
                    设备相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="devtools/dev-tools-screen.html">
            
                <a href="devtools/dev-tools-screen.html">
            
                    
                    屏幕相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="devtools/dev-tools-settings.html">
            
                <a href="devtools/dev-tools-settings.html">
            
                    
                    设置
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../funcs.html">
            
                <a href="../funcs.html">
            
                    
                    功能函数
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="global/global.html">
            
                <a href="global/global.html">
            
                    
                    全局模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="global/global-shortcut.html">
            
                <a href="global/global-shortcut.html">
            
                    
                    全局快捷事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="global/selector-node.html">
            
                <a href="global/selector-node.html">
            
                    
                    选择器&节点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="acevent-api.html">
            
                <a href="acevent-api.html">
            
                    
                    无障碍事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="event-api.html">
            
                <a href="event-api.html">
            
                    
                    代理事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="image-api.html">
            
                <a href="image-api.html">
            
                    
                    图色函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="device-api.html">
            
                <a href="device-api.html">
            
                    
                    设备函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="file-api.html">
            
                <a href="file-api.html">
            
                    
                    文件函数
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7.9" data-path="http-api.html">
            
                <a href="http-api.html">
            
                    
                    网络函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="thread-api.html">
            
                <a href="thread-api.html">
            
                    
                    线程函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="utils-api.html">
            
                <a href="utils-api.html">
            
                    
                    常用工具函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="shell-api.html">
            
                <a href="shell-api.html">
            
                    
                    Shell命令函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="sqlite-api.html">
            
                <a href="sqlite-api.html">
            
                    
                    Sqlite命令函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ui-custom.html">
            
                <a href="ui-custom.html">
            
                    
                    原生UI定制
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="ui-js-inter.html">
            
                <a href="ui-js-inter.html">
            
                    
                    JS编写UI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="ui-js-template.html">
            
                <a href="ui-js-template.html">
            
                    
                    模板式UI
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="ui-native-view.html">
            
                <a href="ui-native-view.html">
            
                    
                    原生UI控件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.3.1" data-path="ui/linearlayout.html">
            
                <a href="ui/linearlayout.html">
            
                    
                    LinearLayout线性布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.2" data-path="ui/framelayout.html">
            
                <a href="ui/framelayout.html">
            
                    
                    FrameLayout帧布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.3" data-path="ui/relativelayout.html">
            
                <a href="ui/relativelayout.html">
            
                    
                    RelativeLayout绝对布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.4" data-path="ui/scrollview.html">
            
                <a href="ui/scrollview.html">
            
                    
                    ScrollView滚动框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.5" data-path="ui/view.html">
            
                <a href="ui/view.html">
            
                    
                    View视图
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.6" data-path="ui/button.html">
            
                <a href="ui/button.html">
            
                    
                    Button按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.7" data-path="ui/textview.html">
            
                <a href="ui/textview.html">
            
                    
                    TextView文本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.8" data-path="ui/edittext.html">
            
                <a href="ui/edittext.html">
            
                    
                    EditText输入框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.9" data-path="ui/checkbox.html">
            
                <a href="ui/checkbox.html">
            
                    
                    CheckBox复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.10" data-path="ui/radiogroup.html">
            
                <a href="ui/radiogroup.html">
            
                    
                    RadioGroup布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.11" data-path="ui/radiobutton.html">
            
                <a href="ui/radiobutton.html">
            
                    
                    RadioButton单选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.12" data-path="ui/spinner.html">
            
                <a href="ui/spinner.html">
            
                    
                    Spinner下拉选择框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.13" data-path="ui/webview.html">
            
                <a href="ui/webview.html">
            
                    
                    WebView内嵌浏览器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.14" data-path="ui/imageview.html">
            
                <a href="ui/imageview.html">
            
                    
                    ImageView图像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.15" data-path="ui/cardview.html">
            
                <a href="ui/cardview.html">
            
                    
                    CardView卡片布局
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3.16" data-path="ui/switch.html">
            
                <a href="ui/switch.html">
            
                    
                    Swtich开关按钮
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="html-ui-custom.html">
            
                <a href="html-ui-custom.html">
            
                    
                    H5 UI定制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../hot-update.html">
            
                <a href="../hot-update.html">
            
                    
                    热更新功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../zk/zk.html">
            
                <a href="../zk/zk.html">
            
                    
                    企业版中控接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../zk/zk-ec-state.html">
            
                <a href="../zk/zk-ec-state.html">
            
                    
                    EC状态控制接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../zk/zk-node.html">
            
                <a href="../zk/zk-node.html">
            
                    
                    全局节点模块接口
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.2.1" data-path="../zk/global/zk-global-log.html">
            
                <a href="../zk/global/zk-global-log.html">
            
                    
                    日志接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.2" data-path="../zk/global/zk-node-service.html">
            
                <a href="../zk/global/zk-node-service.html">
            
                    
                    节点服务接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.3" data-path="../zk/global/zk-global-click.html">
            
                <a href="../zk/global/zk-global-click.html">
            
                    
                    点击动作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.4" data-path="../zk/global/zk-global-multitouch.html">
            
                <a href="../zk/global/zk-global-multitouch.html">
            
                    
                    多点触摸动作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.5" data-path="../zk/global/zk-global-swipe.html">
            
                <a href="../zk/global/zk-global-swipe.html">
            
                    
                    滑动动作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.6" data-path="../zk/global/zk-global-drag.html">
            
                <a href="../zk/global/zk-global-drag.html">
            
                    
                    拖动动作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.7" data-path="../zk/global/zk-global-input.html">
            
                <a href="../zk/global/zk-global-input.html">
            
                    
                    输入动作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.8" data-path="../zk/global/zk-global-node.html">
            
                <a href="../zk/global/zk-global-node.html">
            
                    
                    节点操作接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.9" data-path="../zk/global/zk-global-systemkey.html">
            
                <a href="../zk/global/zk-global-systemkey.html">
            
                    
                    系统按键接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.10" data-path="../zk/global/zk-global-notice.html">
            
                <a href="../zk/global/zk-global-notice.html">
            
                    
                    通知栏接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2.11" data-path="../zk/global/zk-global-floatview.html">
            
                <a href="../zk/global/zk-global-floatview.html">
            
                    
                    悬浮窗接口
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11.3" data-path="../zk/zk-agent.html">
            
                <a href="../zk/zk-agent.html">
            
                    
                    代理事件模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.4" data-path="../zk/zk-image.html">
            
                <a href="../zk/zk-image.html">
            
                    
                    图色模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.5" data-path="../zk/zk-device.md">
            
                <span>
            
                    
                    设备模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.6" data-path="../zk/zk-file.md">
            
                <span>
            
                    
                    文件模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.7" data-path="../zk/zk-http.md">
            
                <span>
            
                    
                    网络模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.8" data-path="../zk/zk-utils.md">
            
                <span>
            
                    
                    常用工具模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.9" data-path="../zk/zk-shell.md">
            
                <span>
            
                    
                    Shell命令模块接口 - 开发中
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.10" data-path="../zk/zk-sqlite.md">
            
                <span>
            
                    
                    Sqlite模块接口 - 开发中
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="plugin/plugins.html">
            
                <a href="plugin/plugins.html">
            
                    
                    插件开发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../question-answer.html">
            
                <a href="../question-answer.html">
            
                    
                    常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../agreement.html">
            
                <a href="../agreement.html">
            
                    
                    用户协议
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../declare.html">
            
                <a href="../declare.html">
            
                    
                    免责声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" >
            
                <span>
            
                    
                    技术交流 QQ群：777164022
            
                </span>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >网络函数</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x8BF4;&#x660E;"><b>1. </b>&#x8BF4;&#x660E;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;"><b>2. </b>&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#httprequest-&#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;"><b>2.1. </b>http.request &#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;</a></li><li><span class="title-icon "></span><a href="#httpdownloadfile"><b>2.2. </b>http.downloadFile</a></li><li><span class="title-icon "></span><a href="#httpdownloadfiledefault"><b>2.3. </b>http.downloadFileDefault</a></li><li><span class="title-icon "></span><a href="#httphttpgetdefault"><b>2.4. </b>http.httpGetDefault</a></li><li><span class="title-icon "></span><a href="#httphttpget"><b>2.5. </b>http.httpGet</a></li><li><span class="title-icon "></span><a href="#httphttppost"><b>2.6. </b>http.httpPost</a></li><li><span class="title-icon "></span><a href="#httppostjson"><b>2.7. </b>http.postJSON</a></li><li><span class="title-icon "></span><a href="#httpnewwebsocket-websocket&#x901A;&#x4FE1;"><b>2.8. </b>http.newWebsocket websocket&#x901A;&#x4FE1;</a></li><ul><li><span class="title-icon "></span><a href="#websocket-&#x5BF9;&#x8C61;&#x51FD;&#x6570;"><b>2.8.1. </b>WebSocket &#x5BF9;&#x8C61;&#x51FD;&#x6570;</a></li></ul></ul></ul></div><a href="#&#x8BF4;&#x660E;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x8BF4;&#x660E;"><a name="&#x8BF4;&#x660E;" class="anchor-navigation-ex-anchor" href="#&#x8BF4;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x8BF4;&#x660E;</h1>
<ul>
<li>&#x7F51;&#x7EDC;&#x6A21;&#x5757;&#x51FD;&#x6570;&#x4E3B;&#x8981;&#x662F;&#x8DDF;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x4FE1;&#x606F;&#x76F8;&#x5173;&#x8054;</li>
<li>&#x7F51;&#x7EDC;&#x6A21;&#x5757;&#x7684;&#x5BF9;&#x8C61;&#x524D;&#x7F00;&#x662F;http&#xFF0C;&#x4F8B;&#x5982; http.downloadFile()&#x8FD9;&#x6837;&#x8C03;&#x7528;</li>
</ul>
<h1 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x51FD;&#x6570;</h1>
<h2 id="httprequest-&#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;"><a name="httprequest-&#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#httprequest-&#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. http.request &#x4E07;&#x80FD;&#x8BF7;&#x6C42;&#x51FD;&#x6570;</h2>
<ul>
<li>HTTP&#x4E07;&#x80FD;&#x8BF7;&#x6C42;</li>
<li>@param param  map&#x53C2;&#x6570;&#xFF0C;&#x5305;&#x542B;&#x7684;&#x53C2;&#x6570;&#x6709;<br><ul>
<li>url:&#x5B57;&#x7B26;&#x4E32; &#x8BF7;&#x6C42;&#x7684;&#x5730;&#x5740;<br></li>
<li>timeout:&#x6574;&#x578B;&#x6BEB;&#x79D2;&#xFF0C;&#x8D85;&#x65F6;&#x65F6;&#x95F4;<br></li>
<li>method: POST ,GET,PUT &#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4EE3;&#x8868;&#x8BF7;&#x6C42;&#x7684;&#x65B9;&#x6CD5;<br></li>
<li>proxy: &#x4EE3;&#x7406;&#x5730;&#x5740;&#xFF0C;map&#x53C2;&#x6570; &#x5305;&#x542B;&#x4E3B;&#x673A;&#x548C;&#x7AEF;&#x53E3; &#x4F8B;&#x5982; {&quot;host&quot;:&quot;11&quot;,&quot;port&quot;:111}<br></li>
<li>followRedirects:&#x662F;&#x5426;&#x81EA;&#x52A8;&#x8DF3;&#x8F6C; true &#x6216;&#x8005; false<br></li>
<li>requestBody: &#x8BF7;&#x6C42;&#x7684;body&#x4F53;&#xFF0C;&#x5982;&#x679C;&#x662F;JSON&#xFF0C;&#x5C31;&#x662F;JSON&#x5B57;&#x7B26;&#x4E32;<br></li>
<li>userAgent:&#x5B57;&#x7B26;&#x4E32; HTTP &#x7684;UA <br></li>
<li>ignoreContentType:&#x662F;&#x5426;&#x5FFD;&#x7565;&#x5185;&#x5BB9;&#x7C7B;&#x578B; true &#x6216;&#x8005; false <br></li>
<li>ignoreHttpErrors:&#x662F;&#x5426;&#x5FFD;&#x7565;&#x9519;&#x8BEF; true &#x6216;&#x8005; false  <br></li>
<li>maxBodySize : &#x6574;&#x578B;&#xFF0C;HTTP BODY&#x6700;&#x5927;&#x503C;  <br></li>
<li>referrer:&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x8BF7;&#x6C42;&#x6765;&#x6E90;  <br></li>
<li>header:  HTTP &#x8BF7;&#x6C42;&#x5934;&#xFF0C;map&#x53C2;&#x6570;,&#x4F8B;&#x5982; {&quot;UA&quot;:&quot;test&quot;}</li>
<li>cookie: HTTP &#x8BF7;&#x6C42;Cookie&#xFF0C;map&#x53C2;&#x6570;, &#x4F8B;&#x5982; {&quot;a&quot;:1} </li>
<li>data:HTTP POST&#x7684;&#x6570;&#x636E;&#xFF0C;map&#x53C2;&#x6570;, &#x4F8B;&#x5982; {&quot;a&quot;:1} </li>
<li>file:&#x8981;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x96C6;&#x5408;&#x53C2;&#x6570;&#xFF0C;&#x4F8B;&#x5982;</li>
<li>[{&quot;key&quot;:&quot;a1&quot;,&quot;fileName&quot;:&quot;a.txt&quot;,&quot;filePath&quot;:&quot;/sdcard/&quot;},{&quot;key&quot;:&quot;a1&quot;,&quot;fileName&quot;:&quot;a.jpg&quot;,&quot;filePath&quot;:&quot;/sdcard/&quot;,&quot;contentType&quot;:&quot;image/jpg&quot;}]<ul>
<li>&#x5176;&#x4E2D;contentType&#x53EF;&#x6709;&#x53EF;&#x65E0;</li>
</ul>
</li>
<li>responseCharset: &#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5F3A;&#x5236;&#x8BBE;&#x7F6E;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x7684;&#x7F16;&#x7801;&#x96C6;</li>
</ul>
</li>
<li>@return Response &#x5BF9;&#x8C61;&#x6216;&#x8005;null</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    http_request();
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">http_request</span>(<span class="hljs-params"></span>) </span>{
   <span class="hljs-comment">//url:string</span>
   <span class="hljs-comment">//timeout:int ms</span>
   <span class="hljs-comment">//method: post ,get</span>
   <span class="hljs-comment">//proxy: {&quot;host&quot;:&quot;11&quot;,&quot;port&quot;:111}</span>
   <span class="hljs-comment">//followRedirects:true false</span>
   <span class="hljs-comment">//requestBody: string</span>
   <span class="hljs-comment">//userAgent:string</span>
   <span class="hljs-comment">//ignoreContentType:true false</span>
   <span class="hljs-comment">//ignoreHttpErrors:true false</span>
   <span class="hljs-comment">//maxBodySize : int</span>
   <span class="hljs-comment">//referrer:string</span>
   <span class="hljs-comment">//header:{&quot;UA&quot;:&quot;test&quot;}</span>
   <span class="hljs-comment">//cookie:{&quot;a&quot;:1}</span>
   <span class="hljs-comment">//data:{&quot;a&quot;:1}</span>
   <span class="hljs-comment">//file:[{}]</span>
   <span class="hljs-comment">//responseCharset: string</span>
   <span class="hljs-keyword">var</span> md = utils.dataMd5(<span class="hljs-string">&quot;12345&quot;</span>);
   <span class="hljs-keyword">var</span> md2 = utils.fileMd5(<span class="hljs-string">&quot;/sdcard/sb.png&quot;</span>);
   <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/request&quot;</span>;
   <span class="hljs-keyword">var</span> proxy = {<span class="hljs-string">&quot;host&quot;</span>: <span class="hljs-string">&quot;192.168.0.5&quot;</span>, <span class="hljs-string">&quot;port&quot;</span>: <span class="hljs-string">&quot;100&quot;</span>};
   <span class="hljs-keyword">var</span> userAgent = <span class="hljs-string">&quot;xxx&quot;</span>;
   <span class="hljs-keyword">var</span> followRedirects = <span class="hljs-literal">false</span>;
   <span class="hljs-keyword">var</span> requestBody = <span class="hljs-built_in">JSON</span>.stringify({<span class="hljs-string">&quot;A&quot;</span>: <span class="hljs-number">111</span>});
   <span class="hljs-keyword">var</span> ignoreContentType = <span class="hljs-literal">true</span>;
   <span class="hljs-keyword">var</span> ignoreHttpErrors = <span class="hljs-literal">true</span>;
   <span class="hljs-keyword">var</span> referrer = <span class="hljs-string">&quot;xxx&quot;</span>;
   <span class="hljs-keyword">var</span> header = {
       <span class="hljs-string">&quot;Content-Type&quot;</span>: <span class="hljs-string">&quot; application/json;  charset=UTF-8&quot;</span>,
       <span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;from test&quot;</span>,
       <span class="hljs-string">&quot;ddd&quot;</span>: md,
       <span class="hljs-string">&quot;dd2&quot;</span>: md2,
       <span class="hljs-string">&quot;imei&quot;</span>: device.getIMEI()
   };
   <span class="hljs-keyword">var</span> cookie = {
       <span class="hljs-string">&quot;cookie1&quot;</span>: <span class="hljs-string">&quot;tst1&quot;</span>,
       <span class="hljs-string">&quot;cookie2&quot;</span>: <span class="hljs-string">&quot;tst2&quot;</span>
   };
   <span class="hljs-keyword">var</span> data = {
       <span class="hljs-string">&quot;a1&quot;</span>: <span class="hljs-string">&quot;aaa&quot;</span>,
       <span class="hljs-string">&quot;pwd2&quot;</span>: md,
       <span class="hljs-string">&quot;md2&quot;</span>: md2
   };
   <span class="hljs-keyword">var</span> file = [
       {
           <span class="hljs-string">&quot;key&quot;</span>: <span class="hljs-string">&quot;file&quot;</span>,
           <span class="hljs-string">&quot;fileName&quot;</span>: <span class="hljs-string">&quot;f.png&quot;</span>,
           <span class="hljs-string">&quot;filePath&quot;</span>: <span class="hljs-string">&quot;/sdcard/sb.png&quot;</span>
       },
       {
           <span class="hljs-string">&quot;key&quot;</span>: <span class="hljs-string">&quot;file&quot;</span>,
           <span class="hljs-string">&quot;fileName&quot;</span>: <span class="hljs-string">&quot;f2.png&quot;</span>,
           <span class="hljs-string">&quot;filePath&quot;</span>: <span class="hljs-string">&quot;/sdcard/sde.png&quot;</span>,
           <span class="hljs-string">&quot;contentType&quot;</span>: <span class="hljs-string">&quot;image/png&quot;</span>
       }
   ];
   <span class="hljs-keyword">var</span> params = {
       <span class="hljs-string">&quot;url&quot;</span>: url,
       <span class="hljs-string">&quot;method&quot;</span>: <span class="hljs-string">&quot;POST&quot;</span>,
       <span class="hljs-string">&quot;userAgent&quot;</span>: userAgent,
       <span class="hljs-string">&quot;referrer&quot;</span>: <span class="hljs-string">&quot;baidu.com&quot;</span>,
       <span class="hljs-string">&quot;cookie&quot;</span>: cookie,
       <span class="hljs-string">&quot;data&quot;</span>: data,
       <span class="hljs-string">&quot;file&quot;</span>: file
   };
   <span class="hljs-keyword">var</span> x = http.request(params);
   <span class="hljs-keyword">if</span> (x) {
       logd(<span class="hljs-string">&quot;header=&gt; &quot;</span> + x.header);
       logd(<span class="hljs-string">&quot;cookie=&gt; &quot;</span> + x.cookie);
       logd(<span class="hljs-string">&quot;statusCode=&gt; &quot;</span> + x.statusCode);
       logd(<span class="hljs-string">&quot;statusMessage=&gt; &quot;</span> + x.statusMessage);
       logd(<span class="hljs-string">&quot;charset=&gt; &quot;</span> + x.charset);
       logd(<span class="hljs-string">&quot;contentType=&gt; &quot;</span> + x.contentType);
       logd(<span class="hljs-string">&quot;body=&gt; &quot;</span> + x.body);
   } <span class="hljs-keyword">else</span> {
       loge(<span class="hljs-string">&quot;&#x65E0;&#x7ED3;&#x679C;&quot;</span>);
   }
}
main();
</code></pre>
</blockquote>
<h2 id="httpdownloadfile"><a name="httpdownloadfile" class="anchor-navigation-ex-anchor" href="#httpdownloadfile"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. http.downloadFile</h2>
<ul>
<li>&#x4E0B;&#x8F7D;&#x8FDC;&#x7A0B;&#x6587;&#x4EF6;&#x5230;&#x672C;&#x5730;,&#x652F;&#x6301;&#x65AD;&#x70B9;&#x7EED;&#x4F20;</li>
<li>@param remoteUrl &#x8FDC;&#x7A0B;&#x6587;&#x4EF6;URL</li>
<li>@param file      &#x8981;&#x4FDD;&#x5B58;&#x5230;&#x672C;&#x5730;&#x7684;&#x6587;&#x4EF6;&#x5BF9;&#x8C61;</li>
<li>@param timeout   &#x4E0B;&#x8F7D;&#x8D85;&#x65F6;&#xFF0C;&#x5355;&#x4F4D;&#x662F;&#x6BEB;&#x79D2;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return true &#x4EE3;&#x8868;&#x6210;&#x529F; false&#x4EE3;&#x8868;&#x5931;&#x8D25;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;https://imtt.dd.qq.com/16891/apk/DF4FD15AF9A9B51BA74D2710CF738EEF.apk?fsname=com.ishugui_3.9.2.3068_3923068.apk&amp;csr=1bbd&quot;</span>;
    <span class="hljs-keyword">var</span> x = http.downloadFile(url, <span class="hljs-string">&quot;/sdcard/ss.apk&quot;</span>, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot;download result-&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httpdownloadfiledefault"><a name="httpdownloadfiledefault" class="anchor-navigation-ex-anchor" href="#httpdownloadfiledefault"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. http.downloadFileDefault</h2>
<ul>
<li>&#x4E0B;&#x8F7D;&#x8FDC;&#x7A0B;&#x6587;&#x4EF6;&#x5230;&#x672C;&#x5730;,&#x652F;&#x6301;&#x65AD;&#x70B9;&#x7EED;&#x4F20;&#xFF0C;&#x9ED8;&#x8BA4;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x4E3A;30&#x79D2;</li>
<li>@param remoteUrl &#x8FDC;&#x7A0B;&#x6587;&#x4EF6;URL</li>
<li>@param file      &#x8981;&#x4FDD;&#x5B58;&#x5230;&#x672C;&#x5730;&#x7684;&#x6587;&#x4EF6;&#x5BF9;&#x8C61;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return true &#x4EE3;&#x8868;&#x6210;&#x529F; false&#x4EE3;&#x8868;&#x5931;&#x8D25;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;https://imtt.dd.qq.com/16891/apk/DF4FD15AF9A9B51BA74D2710CF738EEF.apk?fsname=com.ishugui_3.9.2.3068_3923068.apk&amp;csr=1bbd&quot;</span>;
    <span class="hljs-keyword">var</span> x = http.downloadFileDefault(url, <span class="hljs-string">&quot;/sdcard/ss.apk&quot;</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot;download result-&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httphttpgetdefault"><a name="httphttpgetdefault" class="anchor-navigation-ex-anchor" href="#httphttpgetdefault"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. http.httpGetDefault</h2>
<ul>
<li>Http GET &#x8BF7;&#x6C42;</li>
<li>@param url &#x8BF7;&#x6C42;&#x7684;URL</li>
<li>@param timeout &#x8D85;&#x65F6;&#x65F6;&#x95F4; &#x5355;&#x4F4D;&#x6BEB;&#x79D2;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return &#x5B57;&#x7B26;&#x4E32; &#x8BF7;&#x6C42;&#x540E;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/httpGet?a=1&quot;</span>;
    <span class="hljs-keyword">var</span> x = http.httpGetDefault(url, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot; result-&gt;     &quot;</span> + x);
    loge(<span class="hljs-string">&quot;result -&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httphttpget"><a name="httphttpget" class="anchor-navigation-ex-anchor" href="#httphttpget"><i class="fa fa-link" aria-hidden="true"></i></a>2.5. http.httpGet</h2>
<ul>
<li>Http GET &#x8BF7;&#x6C42;</li>
<li>@param url     &#x8BF7;&#x6C42;&#x7684;URL</li>
<li>@param params  &#x53C2;&#x6570;Map&#x8868; &#x4F8B;&#x5982; {&quot;a&quot;:&quot;1&quot;} &#x8FD9;&#x6837;&#x7684;&#x53C2;&#x6570;&#x6216;&#x8005;&#x5B57;&#x7B26;&#x4E32;</li>
<li>@param timeout &#x8D85;&#x65F6;&#x65F6;&#x95F4; &#x5355;&#x4F4D;&#x6BEB;&#x79D2;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return &#x5B57;&#x7B26;&#x4E32; &#x8BF7;&#x6C42;&#x540E;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/httpGet?a=1&quot;</span>;
    <span class="hljs-keyword">var</span> pa = {<span class="hljs-string">&quot;b&quot;</span>: <span class="hljs-string">&quot;22&quot;</span>};
    <span class="hljs-keyword">var</span> x = http.httpGet(url, pa, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot; result-&gt;     &quot;</span> + x);
    loge(<span class="hljs-string">&quot;result -&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httphttppost"><a name="httphttppost" class="anchor-navigation-ex-anchor" href="#httphttppost"><i class="fa fa-link" aria-hidden="true"></i></a>2.6. http.httpPost</h2>
<ul>
<li>Http Post &#x8BF7;&#x6C42;</li>
<li>@param url     &#x8BF7;&#x6C42;&#x7684;URL</li>
<li>@param params  &#x53C2;&#x6570;&#xFF0C;&#x4F8B;&#x5982; {&quot;a&quot;:&quot;1&quot;} &#x8FD9;&#x6837;&#x7684;&#x53C2;&#x6570;&#x6216;&#x8005;&#x5B57;&#x7B26;&#x4E32;</li>
<li>@param files  &#x8981;&#x4E0A;&#x4F20;&#x7684;&#x6587;&#x4EF6;&#xFF0C;&#x4F8B;&#x5982; {&quot;file1&quot;:&quot;/sdcard/1.png&quot;}&#x8FD9;&#x6837;&#x7684;&#x6587;&#x4EF6;&#x53C2;&#x6570;</li>
<li>@param timeout &#x8D85;&#x65F6;&#x65F6;&#x95F4; &#x5355;&#x4F4D;&#x6BEB;&#x79D2;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return &#x5B57;&#x7B26;&#x4E32; &#x8BF7;&#x6C42;&#x540E;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">//&#x4E0D;&#x5E26;&#x6587;&#x4EF6;&#x7684;&#x8BF7;&#x6C42;</span>
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/httpPost&quot;</span>;
    <span class="hljs-keyword">var</span> pa = {<span class="hljs-string">&quot;b&quot;</span>: <span class="hljs-string">&quot;&#x6211;&#x662F;b&#x7684;&#x503C;&quot;</span>};
    <span class="hljs-keyword">var</span> x = http.httpPost(url, pa, <span class="hljs-literal">null</span>, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot; result-&gt;     &quot;</span> + x);
    loge(<span class="hljs-string">&quot;result -&gt;     &quot;</span> + x);
}
main();
</code></pre>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">//&#x5E26;&#x4E0A;&#x4F20;&#x6587;&#x4EF6;&#x7684;&#x8BF7;&#x6C42;</span>
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/httpPost&quot;</span>;
    <span class="hljs-keyword">var</span> pa = {<span class="hljs-string">&quot;b&quot;</span>: <span class="hljs-string">&quot;&#x6211;&#x662F;b&#x7684;&#x503C;&quot;</span>};
    <span class="hljs-keyword">var</span> files = {<span class="hljs-string">&quot;file1&quot;</span>: <span class="hljs-string">&quot;/sdcard/p.json&quot;</span>, <span class="hljs-string">&quot;file2&quot;</span>: <span class="hljs-string">&quot;/sdcard/z.xml&quot;</span>};
    <span class="hljs-keyword">var</span> x = http.httpPost(url, pa, files, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot; result-&gt;     &quot;</span> + x);
    loge(<span class="hljs-string">&quot;result -&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httppostjson"><a name="httppostjson" class="anchor-navigation-ex-anchor" href="#httppostjson"><i class="fa fa-link" aria-hidden="true"></i></a>2.7. http.postJSON</h2>
<ul>
<li>HTTP POST JSON&#x6570;&#x636E;</li>
<li>@param url &#x8BF7;&#x6C42;&#x7684;URL</li>
<li>@param json  json&#x6570;&#x636E;</li>
<li>@param timeout &#x2013; &#x8D85;&#x65F6;&#x65F6;&#x95F4; &#x5355;&#x4F4D;&#x6BEB;&#x79D2;</li>
<li>@param headers &#x2013; &#x5934;&#x6807;&#x5FD7;&#x4F8B;&#x5982;{&#x201C;a&#x201D;:&#x201C;11&#x201D;}</li>
<li>@return &#x5B57;&#x7B26;&#x4E32; &#x8BF7;&#x6C42;&#x540E;&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-keyword">var</span> url = <span class="hljs-string">&quot;http://192.168.0.5:8081/api/postJSON&quot;</span>;
    <span class="hljs-keyword">var</span> pa = {<span class="hljs-string">&quot;b&quot;</span>: <span class="hljs-string">&quot;&#x6211;&#x662F;b&#x7684;&#x503C;&quot;</span>};
    <span class="hljs-keyword">var</span> x = http.postJSON(url, pa, <span class="hljs-number">10</span> * <span class="hljs-number">1000</span>, {<span class="hljs-string">&quot;User-Agent&quot;</span>: <span class="hljs-string">&quot;test&quot;</span>});
    toast(<span class="hljs-string">&quot; result-&gt;     &quot;</span> + x);
    loge(<span class="hljs-string">&quot;result -&gt;     &quot;</span> + x);
}
main();
</code></pre>
</blockquote>
<h2 id="httpnewwebsocket-websocket&#x901A;&#x4FE1;"><a name="httpnewwebsocket-websocket&#x901A;&#x4FE1;" class="anchor-navigation-ex-anchor" href="#httpnewwebsocket-websocket&#x901A;&#x4FE1;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8. http.newWebsocket websocket&#x901A;&#x4FE1;</h2>
<ul>
<li>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;websocket</li>
<li>@param url &#x8981;&#x8FDE;&#x63A5;&#x7684;&#x5730;&#x5740;</li>
<li>@param header &#x53C2;&#x6570;&#x5934;</li>
<li>@return {@link WebSocket } WebSocket&#x5BF9;&#x8C61;</li>
</ul>
<blockquote>
<pre><code class="lang-javascript">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">//&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;ws&#x8FDE;&#x63A5;</span>
      <span class="hljs-keyword">var</span> ws =http.newWebsocket(<span class="hljs-string">&quot;http://192.168.1.180:9909/ws&quot;</span>,<span class="hljs-literal">null</span>);
      <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x8FDE;&#x63A5;&#x6253;&#x5F00;&#x7684;&#x65F6;&#x5019;&#x76D1;&#x542C;&#x5668;</span>
      ws.onOpen(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ws,code,msg</span>)</span>{
         logi(<span class="hljs-string">&quot;onOpen code &quot;</span>+code +<span class="hljs-string">&quot;  msg:&quot;</span>+msg);
      })
      <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x6709;&#x6587;&#x672C;&#x4FE1;&#x606F;&#x76D1;&#x542C;&#x5668;</span>
       ws.onText(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ws,text</span>)</span>{
            logi(<span class="hljs-string">&quot; onText &quot;</span>+text);
         })
       <span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x5173;&#x95ED;&#x65F6;&#x5019;&#x7684;&#x76D1;&#x542C;&#x5668;</span>
        ws.onClose(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ws,code,reason</span>)</span>{
                logi(<span class="hljs-string">&quot; onClose  &quot;</span>+code +<span class="hljs-string">&quot;  reason : &quot;</span>+reason+<span class="hljs-string">&quot; remote:&quot;</span>);
        })
        ws.onError(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ws,msg</span>)</span>{
                logi(<span class="hljs-string">&quot; onError  &quot;</span>+msg );
        })
        <span class="hljs-comment">// bytes &#x662F; java&#x7684;okio.ByteString &#x5BF9;&#x8C61;</span>
        ws.onBinary(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">ws,bytes</span>)</span>{
                logi(<span class="hljs-string">&quot; onBinary  &quot;</span>+bytes.hex() );
               logi(<span class="hljs-string">&quot; onBinary  &quot;</span>+bytes.utf8() );
               logi(<span class="hljs-string">&quot; onBinary  &quot;</span>+bytes.md5() );
        })
     <span class="hljs-comment">//&#x5F00;&#x59CB;&#x8FDE;&#x63A5;</span>
    ws.connect();
    sleep(<span class="hljs-number">1000</span>)
    <span class="hljs-keyword">if</span> (ws.isConnected()) {
    <span class="hljs-comment">//&#x53D1;&#x9001;&#x6587;&#x672C;</span>
       ws.sendText(<span class="hljs-string">&quot;ping&quot;</span>);
    }
    logd(<span class="hljs-string">&quot;isClosed &quot;</span>+ws.isClosed())
     sleep(<span class="hljs-number">1000</span>)
     <span class="hljs-comment">//&#x5173;&#x95ED;&#x8FDE;&#x63A5;</span>
    ws.close();
}
main();
</code></pre>
</blockquote>
<h3 id="websocket-&#x5BF9;&#x8C61;&#x51FD;&#x6570;"><a name="websocket-&#x5BF9;&#x8C61;&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#websocket-&#x5BF9;&#x8C61;&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8.1. WebSocket &#x5BF9;&#x8C61;&#x51FD;&#x6570;</h3>
<h4 id="connect"><a name="connect" class="anchor-navigation-ex-anchor" href="#connect"><i class="fa fa-link" aria-hidden="true"></i></a>connect</h4>
<ul>
<li>&#x5F00;&#x59CB;&#x5F02;&#x6B65;&#x8FDE;&#x63A5;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="isclosed"><a name="isclosed" class="anchor-navigation-ex-anchor" href="#isclosed"><i class="fa fa-link" aria-hidden="true"></i></a>isClosed</h4>
<ul>
<li>&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5173;&#x95ED;</li>
<li>@return true &#x4EE3;&#x8868;&#x5DF2;&#x7ECF;&#x5173;&#x95ED;&#xFF0C;false &#x672A;&#x5173;&#x95ED;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="isconnected"><a name="isconnected" class="anchor-navigation-ex-anchor" href="#isconnected"><i class="fa fa-link" aria-hidden="true"></i></a>isConnected</h4>
<ul>
<li>&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x8FDE;&#x63A5;&#x4E86;</li>
<li>@return true &#x4EE3;&#x8868;&#x5DF2;&#x7ECF;&#x8FDE;&#x63A5;&#xFF0C;false &#x672A;&#x5173;&#x95ED;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="close"><a name="close" class="anchor-navigation-ex-anchor" href="#close"><i class="fa fa-link" aria-hidden="true"></i></a>close</h4>
<ul>
<li>&#x5173;&#x95ED;&#x94FE;&#x63A5;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="sendtext"><a name="sendtext" class="anchor-navigation-ex-anchor" href="#sendtext"><i class="fa fa-link" aria-hidden="true"></i></a>sendText</h4>
<ul>
<li>&#x53D1;&#x9001;&#x6587;&#x672C;&#x6D88;&#x606F;</li>
<li>@param text &#x6587;&#x672C;&#x4FE1;&#x606F;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="sendbinary"><a name="sendbinary" class="anchor-navigation-ex-anchor" href="#sendbinary"><i class="fa fa-link" aria-hidden="true"></i></a>sendBinary</h4>
<ul>
<li>&#x53D1;&#x9001;&#x5B57;&#x8282;&#x4FE1;&#x606F;</li>
<li>@param bin okio.ByteString &#x5BF9;&#x8C61;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="onopen"><a name="onopen" class="anchor-navigation-ex-anchor" href="#onopen"><i class="fa fa-link" aria-hidden="true"></i></a>onOpen</h4>
<ul>
<li>&#x5F53;&#x8FDE;&#x63A5;&#x6253;&#x5F00;&#x7684;&#x65F6;&#x5019;&#x4E8B;&#x4EF6;&#x56DE;&#x8C03;</li>
<li>@param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="ontext"><a name="ontext" class="anchor-navigation-ex-anchor" href="#ontext"><i class="fa fa-link" aria-hidden="true"></i></a>onText</h4>
<ul>
<li>&#x5F53;&#x6709;&#x6587;&#x672C;&#x4FE1;&#x606F;&#x53D1;&#x9001;&#x8FC7;&#x6765;&#x7684;&#x65F6;&#x5019;&#x56DE;&#x8C03;</li>
<li>@param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="onclose"><a name="onclose" class="anchor-navigation-ex-anchor" href="#onclose"><i class="fa fa-link" aria-hidden="true"></i></a>onClose</h4>
<ul>
<li>&#x5F53;&#x5173;&#x95ED;&#x7684;&#x65F6;&#x5019;&#x56DE;&#x8C03;</li>
<li>@param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="onerror"><a name="onerror" class="anchor-navigation-ex-anchor" href="#onerror"><i class="fa fa-link" aria-hidden="true"></i></a>onError</h4>
<ul>
<li>&#x5F53;&#x53D1;&#x751F;&#x9519;&#x8BEF;&#x7684;&#x65F6;&#x5019;&#x56DE;&#x8C03;</li>
<li>@param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>
<h4 id="onbinary"><a name="onbinary" class="anchor-navigation-ex-anchor" href="#onbinary"><i class="fa fa-link" aria-hidden="true"></i></a>onBinary</h4>
<ul>
<li>&#x5F53;&#x6709;&#x4E8C;&#x8FDB;&#x5236;&#x6570;&#x636E;&#x8FC7;&#x6765;&#x7684;&#x65F6;&#x5019;&#x56DE;&#x8C03;</li>
<li>@param callback &#x56DE;&#x8C03;&#x51FD;&#x6570;</li>
<li>&#x8BE6;&#x7EC6;&#x4EE3;&#x7801;&#x770B;<a href="http-api.html#httpnewwebsocket-websocket&#x901A;&#x4FE1;">&#x4F8B;&#x5B50;</a></li>
</ul>

<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="file-api.html" class="navigation navigation-prev " aria-label="Previous page: 文件函数">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="thread-api.html" class="navigation navigation-next " aria-label="Next page: 线程函数">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"网络函数","level":"1.7.9","depth":2,"next":{"title":"线程函数","level":"1.7.10","depth":2,"path":"zh-cn/funcs/thread-api.md","ref":"zh-cn/funcs/thread-api.md","articles":[]},"previous":{"title":"文件函数","level":"1.7.8","depth":2,"path":"zh-cn/funcs/file-api.md","ref":"zh-cn/funcs/file-api.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","code","copy-code-button","-lunr","-search","search-pro","anchor-navigation-ex","hide-element","favicon-absolute","popup"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"chapter-fold":{},"search-pro":{},"popup":{},"code":{"copyButtons":true},"favicon-absolute":{"appleTouchIconMore":{},"appleTouchIconPrecomposed152":"/zh-cn/images/ico.png","appleTouchIconPrecomposedMore":{},"favicon":"/zh-cn/images/ico.png"},"hide-element":{"elements":[".gitbook-link"]},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"EasyClick开发文档","language":"zh-hans","gitbook":"*","description":"记录EasyClick开发教程和常用的函数"},"file":{"path":"zh-cn/funcs/http-api.md","mtime":"2020-06-23T14:37:56.177Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-06-23T14:38:08.296Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-hide-element/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

